import 'dart:convert';

import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/utils/enumValues.dart';

EvaluationOverviewResult evaluationOverviewResultFromJson(String str) =>
    EvaluationOverviewResult.fromJson(json.decode(str));

String evaluationOverviewResultToJson(EvaluationOverviewResult data) =>
    json.encode(data.toJson());

class EvaluationOverviewResult {
  EvaluationOverviewResult({
    this.status,
    this.message,
    this.result,
  });

  int? status;
  String? message;
  EvaluationOverViewData? result;

  factory EvaluationOverviewResult.fromJson(Map<String, dynamic> json) =>
      EvaluationOverviewResult(
        status: json["status"],
        message: json["message"],
        result: EvaluationOverViewData.fromJson(json["result"]),
      );

  Map<String, dynamic> toJson() => {
        "status": status,
        "message": message,
        "result": result?.toJson(),
      };
}

class EvaluationOverViewData {
  EvaluationOverViewData({
    this.icrLevel,
    this.actflLevel,
    this.studentList,
  });

  List<IcrLevel>? icrLevel;
  List<ActflLevel>? actflLevel;
  List<StudentList>? studentList;

  factory EvaluationOverViewData.fromJson(Map<String, dynamic> json) =>
      EvaluationOverViewData(
        icrLevel: json["ICR Level"] != null
            ? List<IcrLevel>.from(
                json["ICR Level"].map((x) => IcrLevel.fromJson(x)))
            : null,
        actflLevel: json["ACTFL Level"] != null
            ? List<ActflLevel>.from(
                json["ACTFL Level"].map((x) => ActflLevel.fromJson(x)))
            : null,
        studentList: json["studentList"] != null
            ? List<StudentList>.from(
                json["studentList"].map((x) => StudentList.fromJson(x)))
            : null,
      );

  Map<String, dynamic> toJson() => {
        "ICR Level": icrLevel != null
            ? List<dynamic>.from(icrLevel!.map((x) => x.toJson()))
            : null,
        "ACTFL Level": actflLevel != null
            ? List<dynamic>.from(actflLevel!.map((x) => x.toJson()))
            : null,
        "studentList": studentList != null
            ? List<dynamic>.from(studentList!.map((x) => x.toJson()))
            : null,
      };
}

class ActflLevel {
  ActflLevel({
    this.listeningAccuracy,
    this.speakingAiScore,
    this.level,
    this.readingAccuracy,
    this.speakingScore,
    this.writingScore,
  });

  int? listeningAccuracy;
  int? speakingAiScore;
  ACTFLLevel? level;
  int? readingAccuracy;
  int? speakingScore;
  int? writingScore;

  factory ActflLevel.fromJson(Map<String, dynamic> json) => ActflLevel(
        listeningAccuracy:
            json["listeningAccuracy"] != null ? json["listeningAccuracy"] : 0,
        speakingAiScore:
            json["speakingAIScore"] != null ? json["speakingAIScore"] : 0,
        level: actflLevelValues.map[json["level"]],
        readingAccuracy:
            json["readingAccuracy"] != null ? json["readingAccuracy"] : 0,
        speakingScore:
            json["speakingScore"] != null ? json["speakingScore"] : 0,
        writingScore: json["writingScore"] != null ? json["writingScore"] : 0,
      );

  Map<String, dynamic> toJson() => {
        "listeningAccuracy": listeningAccuracy,
        "speakingAIScore": speakingAiScore,
        "level": actflLevelValues.reverse[level],
        "readingAccuracy": readingAccuracy,
        "speakingScore": speakingScore,
        "writingScore": writingScore,
      };
}

final actflLevelValues = EnumValues({
  "Interm-High (15-17)": ACTFLLevel.INTERM_HIGH,
  "Interm-Low (9-11)": ACTFLLevel.INTERM_LOW,
  "Interm-Mid (12-14)": ACTFLLevel.INTERM_MID,
  "Novice-High (7-8)": ACTFLLevel.NOVICE_HIGH,
  "Novice-Low (1-4)": ACTFLLevel.NOVICE_LOW,
  "Novice-Mid (5-6)": ACTFLLevel.NOVICE_MID
});

class IcrLevel {
  IcrLevel({
    this.listeningAccuracy,
    this.speakingAiScore,
    this.level,
    this.readingAccuracy,
    this.speakingScore,
    this.writingScore,
    this.translateScore,
  });

  int? listeningAccuracy;
  int? speakingAiScore;
  int? level;
  int? readingAccuracy;
  int? speakingScore;
  int? writingScore;
  int? translateScore;

  factory IcrLevel.fromJson(Map<String, dynamic> json) => IcrLevel(
      listeningAccuracy:
          json["listeningAccuracy"] != null ? json["listeningAccuracy"] : 0,
      speakingAiScore:
          json["speakingAIScore"] != null ? json["speakingAIScore"] : 0,
      level: json["level"],
      readingAccuracy:
          json["readingAccuracy"] != null ? json["readingAccuracy"] : 0,
      speakingScore: json["speakingScore"] != null ? json["speakingScore"] : 0,
      writingScore: json["writingScore"] != null ? json["writingScore"] : 0,
      translateScore:
          json["translateScore"] != null ? json["translateScore"] : 0);

  Map<String, dynamic> toJson() => {
        "listeningAccuracy": listeningAccuracy,
        "speakingAIScore": speakingAiScore,
        "level": level,
        "readingAccuracy": readingAccuracy,
        "speakingScore": speakingScore,
        "writingScore": writingScore,
        "translateScore": translateScore,
      };
}

class StudentList {
  StudentList({
    this.firstName,
    this.lastName,
    this.icrLevel,
    this.actflLevel,
    this.userName,
  });

  String? firstName;
  String? lastName;
  List<IcrLevel>? icrLevel;
  List<ActflLevel>? actflLevel;
  String? userName;

  factory StudentList.fromJson(Map<String, dynamic> json) => StudentList(
        firstName: json["firstName"],
        lastName: json["lastName"],
        icrLevel: json["ICR Level"] != null
            ? List<IcrLevel>.from(
                json["ICR Level"].map((x) => IcrLevel.fromJson(x)))
            : null,
        actflLevel: json["ACTFL Level"] != null
            ? List<ActflLevel>.from(
                json["ACTFL Level"].map((x) => ActflLevel.fromJson(x)))
            : null,
        userName: json["userName"],
      );

  Map<String, dynamic> toJson() => {
        "firstName": firstName,
        "lastName": lastName,
        "ICR Level": icrLevel != null
            ? List<dynamic>.from(icrLevel!.map((x) => x.toJson()))
            : null,
        "ACTFL Level": actflLevel != null
            ? List<dynamic>.from(actflLevel!.map((x) => x.toJson()))
            : null,
        "userName": userName,
      };
}
